import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.acl.Owner;

import javax.swing.*;


public class ButtonPanel extends JPanel {
	public ButtonPanel() {
		this.addButton("Red", Color.RED);
		this.addButton("Green", Color.GREEN);
		this.addButton("Blue", Color.BLUE);		
	}
	
	private void addButton(String buttonName, Color aColor){
		JButton button = new JButton(buttonName);
		this.add(button);
		
		ColorAction action = new ColorAction(aColor);
		button.addActionListener(action);
	}
	
	private class ColorAction implements ActionListener{
		private Color bgrColor;
		
		public ColorAction(Color aColor){
			this.bgrColor = aColor;			
		}
		
		public void actionPerformed(ActionEvent arg0) {
			setBackground(this.bgrColor);			
		}
	}
}
